class PerformanceCalculator {

  // 将参数play的初始化操作放到此处
  // 把数据转换移动到同一个地方，保证了代码的一致性和清晰度
  // 改变函数声明
  constructor(performance, play) {
    this.performance = performance;
    this.play = play;
  }

// 获取金额，交由子类实现
  get amount() {
    throw new Error("Not Supper Performance Type");
  }

  // 获取积分，交由子类实现
  get volumeCredits() {
    return Math.max(this.performance.audience - 30, 0);;
  }

}

// 子类取代类型码
class TragedyCalculator extends PerformanceCalculator {

  get amount() {
    let result = 40000;
    if (this.performance.audience > 30) {
      result += 1000 * (this.performance.audience - 30);
    }
    return result;
  }

}

class ComedyCalculator extends PerformanceCalculator {
  get amount() {
    let result = 30000;
    if (this.performance.audience > 20) {
      result += 10000 + 500 * (this.performance.audience - 20);
    }
    return result;
  }

  get volumeCredits() {
    return super.volumeCredits + Math.floor(this.performance.audience / 5);
  }
}

export {TragedyCalculator, ComedyCalculator};


